package cn.tedu.mvcboot01.controller;

import cn.tedu.mvcboot01.pojo.dto.BmiDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    /**BMI身体质量指数测试：声明参数方式接收客户端传递的数据*/
    /*
    @RequestMapping("/bmi")
    @ResponseBody
    public String bmiControl(double height, double weight){
        // soutp + Enter
        System.out.println("height = " + height + ", weight = " + weight);
        double result = weight / (height * height);
        if (result < 18.5){
            return "偏瘦";
        }
        if (result < 24){
            return "正常";
        }
        if (result < 27){
            return "微胖";
        }
        return "该减肥了";
    }

     */

    /**BMI身体质量指数测试：使用pojo类的方式接收客户端传递的数据*/
    @RequestMapping("/bmi")
    @ResponseBody
    public String BmiControl(BmiDTO bmiDTO){
        double height = bmiDTO.getHeight();
        double weight = bmiDTO.getWeight();
        double result = weight / (height * height);

        if (result < 18.5){
            return "兄弟你瘦了";
        }
        if (result < 24){
            return "身体倍儿棒";
        }
        if (result < 27){
            return "身体微微胖";
        }
        return "兄弟你真该减肥了！";
    }
}









